<?php

/**
 * 快递相关渠道
 */
class Application_Model_ExpressChannel extends Application_Model_DomainObject{
    
    protected $_id;
    
    protected $_name;
    
    protected $_expressId;
    
    protected $_key;
    
    protected $_code;
    
    protected $_expressUrl;
    
    protected $_agentCompanyId;
    
    protected $_isShipNo;


    public static function getChannel($name)
    {
        return Application_Model_DbTable_ExpressChannel::getChannelOne($name);
    }
    
    /**
     * 根据快递ID返回可以选择的发贷渠道
     * @param type $expressId
     * @return type
     */
    public static function getByExpressId($expressId){
        return self::getDao()->queryAll(array('expressId'=>$expressId));
    }
    
    public static function getByACId($acId){
        return self::getDao()->queryAll(array("agentCompanyId = "=>$acId));
    }
    
    public function getExpressName()
    {
        if($this->_expressId != ""){
            return Application_Model_Express::load($this->_expressId)->Name;
        } else {
            return "其他";
        }
    }
    
    public function getAgentCompanyName()
    {
        if($this->_agentCompanyId){
            return Application_Model_AgentCompany::load($this->_agentCompanyId)->Name;
        } else {
            return "其他";
        }
    }
    
    public static function getPriceFilteds($quick,$expressId,$actId,$isShipNo,$pagesize,$pageindex)
    {
        $where = array();
        $and = "";
        if($quick != "")
        {
            $where[$and." ( name like "] = "%".$quick."%";
            $and = " or ";
            $where[$and." `key` like "] = "%".$quick."%";
            $where[" ) and 1 = "] = 1;
            $and = " and ";
        }
        if($expressId !== "")
        {
            $where[$and." expressId = "] = $expressId;
            $and = " and ";
        }
        if($actId !== "")
        {
            $where[$and." agentCompanyId = "] = $actId;
            $and = " and ";
        }
        if($isShipNo !== "")
        {
            $where[$and." isShipNo = "] = $isShipNo;
            $and = " and ";
        }
//        var_dump($where);exit;
        return self::getDao()->queryPage($where, " id asc ", $pagesize, $pageindex);
    }
}